package main

import (
	"github.com/micro/go-micro"
	"github.com/micro/go-micro/registry"
	"github.com/micro/go-micro/service/grpc"
	"github.com/micro/go-micro/util/log"
	"github.com/micro/go-plugins/registry/consul"
	"shopping/product/db"
	"shopping/product/handler"
	"shopping/product/repository"
	product "shopping/product/proto/product"
)

func main() {


	repo := &repository.Product{db.MastDB}

	// boot trace
	//TraceBoot()

	reg:= consul.NewRegistry(func(op *registry.Options) {
		op.Addrs = []string{
			"127.0.0.1:8500",
		}

	})

	// New Service
	service := grpc.NewService(
		micro.Registry(reg),
		micro.Name("go.micro.srv.product"),
		micro.Version("latest"),
		//micro.WrapHandler(wrapperTrace.NewHandlerWrapper()),
		//micro.WrapClient(wrapperTrace.NewClientWrapper()),
	)

	// Initialise service
	service.Init()

	// Register Handler
	product.RegisterProductServiceHandler(service.Server(), &handler.Product{repo})

	// Register Struct as Subscriber
	//micro.RegisterSubscriber("go.micro.srv.product", service.Server(), new(subscriber.Example))

	// Register Function as Subscriber
	//micro.RegisterSubscriber("go.micro.srv.product", service.Server(), subscriber.Handler)

	// Run service
	if err := service.Run(); err != nil {
		log.Fatal(err)
	}
}
